package com.spring.sunflower.dialog;

import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;

import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.enums.PopupAnimation;
import com.spring.sunflower.R;
import com.spring.sunflower.common.TaskActivity;

/**
 * Created by Kevin on 2021/9/1<br/>
 * <p>
 * Describe:<br/>
 */
public class TaskFinishDialogUtils {
    private static TaskFinishDialogUtils mInstance;

    public static TaskFinishDialogUtils getInstance() {
        if (mInstance == null) {
            synchronized (TaskFinishDialogUtils.class) {
                if (mInstance == null) {
                    mInstance = new TaskFinishDialogUtils();
                }
            }
        }
        return mInstance;
    }

    public void show(Activity context, String award) {
        TaskFinishDialog taskFinishDialog = new TaskFinishDialog(context);
        taskFinishDialog.setOnTaskFinishListener(new TaskFinishDialog.OnTaskFinishListener() {
            @Override
            public void onCrateView() {
                TextView tvAward = taskFinishDialog.findViewById(R.id.tvAward);
                tvAward.setText(award);
            }

            @Override
            public void onMoreClick() {
                context.startActivity(new Intent(context, TaskActivity.class));
            }
        });
        new XPopup.Builder(context)
                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                .isRequestFocus(false)
                .dismissOnTouchOutside(false)
                .autoDismiss(false)
                .asCustom(taskFinishDialog)
                .show();
    }
}
